package by.bsu.fpmi.bbtp.dao;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.io.Serializable;
import java.util.List;

public abstract class AbstractDAO<T> extends HibernateDaoSupport {

    protected abstract Class<T> getClassOfObject();
    
    public void save(T object) {
        getHibernateTemplate().saveOrUpdate(object);
    }
    
    public T find(Serializable id) {
        Object object = getHibernateTemplate().get(getClassOfObject(), id);
        return getClassOfObject().cast(object);
    }

    public List<T> all() {
        return getHibernateTemplate().loadAll(getClassOfObject());
    }
    
    public void remove(T object) {
        getHibernateTemplate().delete(object);
    }
}
